package com.nanhai.buddhist.college.module.study.dal.mysql.studysubject;

import java.util.*;

import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.mybatis.core.enums.DefaultFuncEnumX;
import com.nanhai.buddhist.college.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.nanhai.buddhist.college.framework.mybatis.core.mapper.BaseMapperX;
import com.nanhai.buddhist.college.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.nanhai.buddhist.college.module.study.dal.dataobject.studysubject.StudySubjectDO;
import com.nanhai.buddhist.college.module.study.dal.dataobject.subjectconfig.StudySubjectConfigDO;
import org.apache.ibatis.annotations.Mapper;
import com.nanhai.buddhist.college.module.study.controller.admin.studysubject.vo.*;

/**
 * 课程管理 Mapper
 *
 * @author xqenzo@163.com
 */
@Mapper
public interface StudySubjectMapper extends BaseMapperX<StudySubjectDO> {

    default PageResult<StudySubjectDO> selectPage(StudySubjectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<StudySubjectDO>()
                .likeIfPresent(StudySubjectDO::getName, reqVO.getName())
                .eqIfPresent(StudySubjectDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(StudySubjectDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StudySubjectDO::getCreateTime));
    }

    default PageResult<StudySubjectDO> selectPage0(StudySubjectPageReqVO reqVO) {
        return selectPageForJoin(reqVO, StudySubjectDO.class, new MPJLambdaWrapperX<StudySubjectDO>()
                .likeIfPresent(StudySubjectDO::getName, reqVO.getName())
                .eqIfPresent(StudySubjectDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(StudySubjectDO::getCreateTime, reqVO.getCreateTime())
                .leftJoin(StudySubjectConfigDO.class, StudySubjectConfigDO::getStudySubjectId, StudySubjectDO::getId)
                .selectAll(StudySubjectDO.class)
                .selectFunc(DefaultFuncEnumX.LENGTH,StudySubjectConfigDO::getStudySubjectId, StudySubjectDO::getConfigStatus)
                .orderByDesc(StudySubjectDO::getCreateTime));
    }

    default List<StudySubjectDO> selectList(StudySubjectExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<StudySubjectDO>()
                .likeIfPresent(StudySubjectDO::getName, reqVO.getName())
                .eqIfPresent(StudySubjectDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(StudySubjectDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StudySubjectDO::getCreateTime));
    }

}
